package com.knight.jdk8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Description:
 * @author: knight
 * @Date: 2019-05-04 18:09
 */
public class StreamTest8 {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("hello", "world", "hello world");
        // 输出长度为5的第一个单词
        list.stream().filter(e -> e.length() == 5).findFirst().ifPresent(System.out::println);

        System.out.println("--------------");
        // 将集合中的单词去重输出
        List<String> strings = Arrays.asList("hello welcome", "world hello", "hello world hello", "hello welcome");
        String[] stringArray = {"hello ", "welcome", "world", "hello", "hello","world","hello", "hello","welcome"};
        List<String[]> arrayList = new ArrayList<>();
        arrayList.add(stringArray);
        arrayList.stream().flatMap(e -> Arrays.stream(e)).forEach(System.out::println);
        System.out.println("---------------");
        strings.stream().map(e -> e.split(" ")).flatMap(e2->Arrays.stream(e2)).distinct()
                .collect(Collectors.toList()).forEach(System.out::println);


    }
}
